import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import local_get from '@dfeidao/atom-web/local/get';
import local_remove from '@dfeidao/atom-web/local/remove';
import local_set from '@dfeidao/atom-web/local/set';
import render from '@dfeidao/atom-web/render/render';
import P01 from './P01';
// 删除控制点
export default async function a005(fd: IFeidaoAiBrowserComponent, args?: { currentTarget: HTMLElement }) {
	const data = local_get(fd, "data") as [];
	const new_data = new Array();
	Array.from(data).forEach((a) => {
		if (JSON.stringify(a) !== args.currentTarget.getAttribute('data')) {
			new_data.push(a);
		}
	});
	render(fd, { dataArray: new_data }, P01, 'P01', 'inner');
	local_set(fd, "data", new_data);
	// 判断删除的数据是暂存的，还是原始的并进行删除数据的存储
	const original_data = local_get(fd, "original_data") as [];// 原始数据

	const x: [] = local_get(fd, "del_data");
	let del_data = new Array();
	if (x) {
		del_data = x;
	}
	const code = JSON.parse(args.currentTarget.getAttribute('data')).code.toString();
	Array.from(original_data).forEach((a: { code: string }) => {
		if (a.code === code) {
			del_data.push(a.code);
		}
	});
	if (del_data.length > 0) {
		local_set(fd, "del_data", del_data);
	} else {
		local_remove(fd, "del_data");
	}
}
